package com.hanserwei.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("direct.exchange", true, false);
    }

    @Bean
    public Queue directQueue1() {
        return new Queue("direct.queue1", true, false, false);
    }

    @Bean
    public Queue directQueue2() {
        return new Queue("direct.queue2", true, false, false);
    }

    @Bean
    public Binding directBinding1() {
        return BindingBuilder.bind(directQueue1()).to(directExchange()).with("a");
    }

    @Bean
    public Binding directBinding2() {
        return BindingBuilder.bind(directQueue2()).to(directExchange()).with("b");
    }
    
    @Bean
    public Binding directBinding3() {
        return BindingBuilder.bind(directQueue2()).to(directExchange()).with("c");
    }
    
    @Bean
    public Binding directBinding4() {
        return BindingBuilder.bind(directQueue2()).to(directExchange()).with("a");
    }


    // TOPIC 模式
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("topic.exchange", true, false);
    }

    @Bean
    public Queue topicQueue1() {
        return new Queue("topic.queue1", true, false, false);
    }

    @Bean
    public Queue topicQueue2() {
        return new Queue("topic.queue2", true, false, false);
    }

    @Bean
    public Queue topicQueue3() {
        return new Queue("topic.queue3", true, false, false);
    }

    @Bean
    public Binding topicBinding1() {
        return BindingBuilder.bind(topicQueue1()).to(topicExchange()).with("a.*");
    }

    @Bean
    public Binding topicBinding2() {
        return BindingBuilder.bind(topicQueue2()).to(topicExchange()).with("*.#");
    }

    @Bean
    public Binding topicBinding3() {
        return BindingBuilder.bind(topicQueue3()).to(topicExchange()).with("*.b");
    }

}
